package com.lyl.cloud.common.base;

import cn.hutool.core.collection.ListUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.List;

@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class Result {

    public static final List<Object> DEFAULT_DATA = ListUtil.empty();
    public static final String SUCCESS_MSG = "请求成功";
    public static final String FAIL_MSG = "请求失败";
    private String code;
    private boolean state;
    private String msg;
    private Object data;

    public static Result success() {
        return success(DEFAULT_DATA);
    }

    public static Result success(Object data) {
        return success(SUCCESS_MSG, data);
    }
    
    public static Result success(String msg, Object data){
        return builder("200",true,msg,data);
    }

    public static Result fail() {
        return fail(DEFAULT_DATA);
    }

    public static Result fail(Object data) {
        return fail(FAIL_MSG, data);
    }

    public static Result fail(String msg, Object data){
        return builder("400",false,msg,data);
    }

    public static Result builder(String code, boolean state, String msg) {
        return builder(code, state, msg, DEFAULT_DATA);
    }
    
    
    public static Result builder(String code, boolean state, String msg, Object data) {
        return new Result(code, state, msg, data);
    }
}
